package com.btcode.web.mvc.errorhandle;

import com.btcode.common.AbstractSingleton;
import com.btcode.web.core.errorhandle.IErrorHandler;
import com.btcode.web.core.respone.JsonRespone;
import com.btcode.web.core.respone.ResultFlag;
import java.io.IOException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 默认的API
 *
 * @author gislin
 */
public class DefaultApiErrorHandler implements IErrorHandler {

    @Override
    public void handleError(ServletRequest arg0, ServletResponse arg1, Throwable throwable) {
        String msgStr = "";

        if (throwable != null) {
            msgStr = throwable.getMessage();
        }

        try {
            AbstractSingleton.getInstance(JsonRespone.class).outputObj(null, ResultFlag.ERROR,
                                                                       msgStr);
        }
        catch (IOException e1) {
            e1.printStackTrace();
        }
    }

}